import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    userInfo: {},
    idInfo: {}
  },
  mutations: {
    setUserInfo(state, value) {
      state.userInfo = value;
    },
    setIdInfo(state, value) {
      state.idInfo = value;
    },
  },
  plugins: [createPersistedState(
    {
      storage: window.sessionStorage,
      reducer(val) {
        return {
          userInfo: val.userInfo,
          idInfo: val.idInfo
        }
      }
    }
  )]
})

export default store
